/*
 * Copyright 2010 Katsunori Koyanagi
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package sweezy.anim.impl
{
	import sweezy.anim.core.IEasing;

	internal class EasingAnimation extends AnimationDecoratorBase
	{

		private var _easing:IEasing;

		public function EasingAnimation(manager:AnimationManager, animation:AnimationBase, easing:IEasing)
		{
			super(manager, animation);

			if (easing === null)
			{
				easing = manager.defaultEasing;
			}
			_easing = easing;
		}

		override public function get parameters():Object
		{
			return {easing: _easing};
		}

		override protected function onInitializeInternal():void
		{
			_targetAnimation.initialize();
			_duration = _targetAnimation._duration;
		}

		override protected function onUpdateInternal():void
		{
			if (_easing === null || _position === -1 || _position === 0 || _position === _duration)
			{
				_targetAnimation.position = _position;
				return;
			}

			_targetAnimation.position = _easing.ease(_position / _duration) * _position;
		}
	}
}
